//
//  ServiceProvisionViewController.m
//  BusinessApp
//
//  Created by CccDaxIN on 2016/10/26.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "ServiceProvisionViewController.h"

@interface ServiceProvisionViewController ()<UIWebViewDelegate>

@end

@implementation ServiceProvisionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = [NNSingleton sharedSingleton].titlt_string;
    self.view.backgroundColor = [UIColor whiteColor];
    
    /*
     *返回
     */
    UIImage *serviceProvisionBackImage = [UIImage imageNamed:@"左箭头"];
    serviceProvisionBackImage = [serviceProvisionBackImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:serviceProvisionBackImage style:UIBarButtonItemStylePlain target:self action:@selector(serviceProvisionBackAction)];
    
    if ([[NNSingleton sharedSingleton].titlt_string isEqualToString:@"入驻协议"]) {
        /*
         *入驻协议单独的接口
         */
        [self settledAgreementDataRequest];
        
    }else{
        [self getTheSellerAgreementDataRequest];
    }

    // Do any additional setup after loading the view.
}
- (void)serviceProvisionBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- 根据title获取条款内容 接口
- (void)getTheSellerAgreementDataRequest{
    
    [GDJHttpTool get:ServiceProvision params:@{@"ShouJiHao":GETPHONE,@"Duuid":GETUUID,@"Token":GETTOKEN,@"Title":[NNSingleton sharedSingleton].titlt_string} success:^(id responseObj) {
        NSLog(@"燃烧吧 ： %@",responseObj);
        [SVProgressHUD showWithStatus:@"正在加载"];
        //查看错误码
        NSInteger err = [[responseObj valueForKey:@"Err"]integerValue];
        NSLog(@"争取吧%ld %@",(long) err,responseObj[@"ErrMsg"]);
        if (err == 0) {
            [SVProgressHUD dismiss];
            
            UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0,64,kScrernWidth, kScrernHeight-64)];
            webview.backgroundColor = [UIColor whiteColor];
            [webview setUserInteractionEnabled:YES];//是否支持交互
            webview.delegate=self;
//            [webview setOpaque:NO];//opaque是不透明的意思
//            [webview setScalesPageToFit:YES];//自动缩放以适应屏幕
            [self.view addSubview:webview];
            
            NSString *string_url = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,responseObj[@"Article"][@"Url"]];
            NSURL *url = [NSURL URLWithString:string_url];
            [webview loadRequest:[NSURLRequest requestWithURL:url]];

        }else{
            [SVProgressHUD showErrorWithStatus:@"数据加载失败" ];
        }
    }failure:^(NSError *error) {
        NSLog(@"error::%@",error);
    }];
}
#pragma mark -- 入驻协议接口
- (void)settledAgreementDataRequest{
    
    [GDJHttpTool get:SellerAgreement params:@{@"ShouJiHao":GETPHONE,@"Duuid":GETUUID,@"Token":GETTOKEN} success:^(id responseObj) {
        NSLog(@"小宇宙 ： %@",responseObj);
        [SVProgressHUD showWithStatus:@"正在加载"];
        //查看错误码
        NSInteger err = [[responseObj valueForKey:@"Err"]integerValue];
        NSLog(@"争取吧%ld %@",(long) err,responseObj[@"ErrMsg"]);
        if (err == 0) {
            [SVProgressHUD dismiss];
            
            UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0,64,kScrernWidth, kScrernHeight-64)];
            webview.backgroundColor = [UIColor whiteColor];
            [webview setUserInteractionEnabled:YES];//是否支持交互
            webview.delegate=self;
            [self.view addSubview:webview];
            NSString *string_url = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,responseObj[@"Agreement"][@"Url"]];
            NSURL *url = [NSURL URLWithString:string_url];
            [webview loadRequest:[NSURLRequest requestWithURL:url]];
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"数据加载失败" ];
        }
    }failure:^(NSError *error) {
        NSLog(@"error::%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
